
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>经济管理学院</title>
<link rel="stylesheet" href='css/style.css' type="text/css">

</head>
<script type='text/javascript' src='js/prototype.js'></script>
<script type='text/javascript' src='js/sha1.js'></script>
<script type='text/javascript' src='js/public.js'></script>
<script type="text/javascript">
var start;
var stop;
var shake;
var request = {
		QueryString : function(val) {
			var uri = window.location.search;
			var re = new RegExp("" + val + "=([^&?]*)", "ig");
			return ((uri.match(re)) ? (uri.match(re)[0]
					.substr(val.length + 1)) : null);
		}
	};
	
function showuserkey(){
	var params = "user_keyName=userName&user_keyName=privilegeToCreateLecture";
	new Ajax.Request("json/showUser_key", {
		method : "post",
		parameters : params,
		onComplete : function(request) {
			var res = request.responseText.evalJSON();
		
			if(res["result"]["userName"]==null||res["result"]["privilegeToCreateLecture"]=="0")
				window.location.href="login.html";
			document.getElementById("username").innerHTML = "欢迎 "
				+ res["result"]["userName"];
		},
		asynchronous : true
	});
	online();
	viewLecturesOutline();
}

function viewLecturesOutline() {

    var lectureId = request.QueryString("lectureId");
	var params = "lectureId=" + encodeURIComponent(lectureId);
	
	
	new Ajax.Request(
			"json/viewLecturesOutline",
			{
				method : "post",
				parameters : params,
				onComplete : function(request) {
					var res = request.responseText.evalJSON();
					
			
					if (res["result"]["flag"] == "true") {
						var grade=" ";
						if(res["result"]["userEnterYear1"]!==null)
						 grade += res["result"]["userEnterYear1"]+" ";
						if(res["result"]["userEnterYear2"]!==null)
							 grade += res["result"]["userEnterYear2"]+" ";
						if(res["result"]["userEnterYear3"]!==null)
							 grade += res["result"]["userEnterYear3"]+" ";
						if(res["result"]["userEnterYear4"]!==null)
							 grade += res["result"]["userEnterYear4"]+" ";
						 start= compareTime(res["result"]["startTime"]);
						 stop=compareTime(res["result"]["stopTime"]);
						 shake=res["result"]["shake"];
					     var status="";
						if(start=="大于")
							status+="未到报名时间"+res["result"]["startTime"];
						if(start=="小于"&stop=="大于")
						   status+="正在报名中 截止时间"+res["result"]["stopTime"];
						if(stop=="小于")
							status+="报名已经截止 等待报名结果";
						var str=res["result"]["lecYear"];
						var lecyear1 = str.substr(0,4);
						　　 str = str.replace(lecyear1,'');
					    var lecyear2=str.substr(0,4);
						    str = str.replace(lecyear2,'');
						var lecterm=str.substr(0,1);
						var tmp = "<ul style='width:100%; border-bottom:1px  #999 dotted;'><li style='margin-left:20px;margin-top:20px;'>学期："+lecyear1+"——"+lecyear2+"学期 第"+lecterm+"学期</li><li style='margin-left:20px; '>主题："
						+res["result"]["lecName"]
						+" </li><li style='margin-left:20px;'>主讲人："+res["result"]["lecSpeaker"]
						+"</li><li style='margin-left:20px;'>举办时间："+res["result"]["lecTime"]
						+"</li><li style='margin-left:20px;'>举办地点："+res["result"]["lecPlace"]
						+"</li><li style='margin-left:20px;''>参与年级："+grade
						+"</li><li style='margin-left:20px;'>报名开始时间："+res["result"]["startTime"]
						+"</li><li style='margin-left:20px;'>报名截止时间："+res["result"]["stopTime"]
						+"</li><li style='margin-left:20px;''>备注："+ res["result"]["lecNote"]
						+ "</li><li style='margin-left:20px;'>发放票数："+res["result"]["lecCodeNumber"]
						+"</li><li style='margin-left:20px;'>报名人数："+res["result"]["registerNum"]
						+"</li><li style='margin-left:20px;'>签到人数："+res["result"]["checkNum"]
						+"</li></ul>";
						$("iteratorProductsTarget").innerHTML += tmp;
						//document.getElementById("editor").innerHTML = "<a href='editorLecture.jsp?lectureId="+lectureId+"&who="+res["result"]["lecSpeaker"]+"&lecName="+res["result"]["lecName"]+"&lecTime="+res["result"]["lecTime"]+"&lecPlace="+res["result"]["lecPlace"]+"&grade1="+res["result"]["userEnterYear1"]+"&grade2="+res["result"]["userEnterYear2"]+"&grade3="+res["result"]["userEnterYear3"]+"&grade4="+res["result"]["userEnterYear4"]+"&starttime="+res["result"]["startTime"]+"&stoptime="+res["result"]["stopTime"]+"&num="+res["result"]["lecCodeNumber"]+"'>修改</a>"
							
							document.getElementById("showcode").innerHTML = "<a href='showCode.html?lectureId="+lectureId+"' target='_blank'>查看验证码</a>"	;
							document.getElementById("showregister").innerHTML = "<a href='showRegister.html?lectureId="+lectureId+"&shake="+res["result"]["shake"]+"' target='_blank'>查看摇号结果</a>";
							document.getElementById("showcheck").innerHTML = "<a href='showCheck.html?lectureId="+lectureId+"' target='_blank'>签到结果</a>"	;
							if(stop=="小于")
								{
								document.getElementById("editor").innerHTML = "不可修改"	;
								}
							else{
								document.getElementById("editor").innerHTML = "<a href='editorLecture.html?lectureId="+lectureId+"' >修改</a>"	;
							}
							if(shake=="1")
								{
								document.getElementById("shakeli").innerHTML = "已摇号"	;
								}
							else{
								document.getElementById("shakeli").innerHTML = "<input type='button' value='摇号' onclick='lecshake()'>"	;
							}
								
					}
				},
				asynchronous : false
			});
}


function deleteLecture() {
	if(shake=="1"||stop=="小于")
		{alert("讲座正在使用或已关闭，不可删除！")}
	
	else if(confirm("确定删除？"))
		{

    var lectureId = request.QueryString("lectureId");
	var params = "lectureId=" + encodeURIComponent(lectureId);
	
	new Ajax.Request("json/deleteLecture", {
		method : "post",
		parameters : params,
		onComplete : function(request) {
			var res = request.responseText.evalJSON();
			
			
			if (res["result"]["flag"] == "true") {
				alert("成功删除");
				window.location.href="TeacherIndex.html";
			}
		},
		asynchronous : false
	});}
}


function lecshake() {
	if(stop=="小于")
   {
    var lectureId = request.QueryString("lectureId");
	var params = "lectureId=" + lectureId;
	alert("摇号可能需要一定的时间，请耐心等待");
	new Ajax.Request("json/shake", {
		method : "post",
		parameters : params,
		onComplete : function(request) {
			var res = request.responseText.evalJSON();
		
		if(res["result"]["flag"]=="true")
			{
			alert("已经完成摇号，可在查看摇号结果中查看结果");
			}
			
		
		},
		asynchronous : false
	});}
	else
		alert("请等到报名结束后摇号");
}
function teacherRegisterLecture(){
	var studentId=document.getElementById("studentId").value;
	var lectureId = request.QueryString("lectureId");
	if(shake=="0"){
		alert("请先摇号");
	}
	else if(studentId=="")
		{alert("请输入学号");}
	else{
	var params = "stuentId=" + encodeURIComponent(studentId) + "&lectureId=" + lectureId;
	new Ajax.Request("json/teacherRegisterLecture", {
		method : "post",
		parameters : params,
		onComplete : function(request) {
			var res = request.responseText.evalJSON();
			
			if(res["result"]["errormessage"]=="true")
				{alert("该用户不存在");}
			else if (res["result"]["flag"] == "true") {
				alert("已成功报名");
				
				
			}
			else{
				alert("改学号已经报名，无须手动报名");
			}
		},
		asynchronous : false
	});
	}
		
}
</script>
<body onload="showuserkey()">
	<div id="header">

		<div id="nav">
			<ul
				style="float: left; padding: 0 20px; text-align: center; line-height: 50px;">
				<li style="float: left; font-size: 28px">经管院学术讲坛事务系统</li>
			</ul>
			<ul class="horizon">

				<li class="login">
					<ul class="vertical">
						<li class="userInfo" id="username">&nbsp;你好</li>
						<li class="userInfo2">
							<ul class="horizon">

								<li><a href="adminUser.html" target="_blank"
									style="text-decoration: none;">用户信息管理</a><br /> <a
									onclick="outline()" style="text-decoration: none;" href="#">注销</a></li>
							</ul>
						</li>
					</ul>
				</li>

			</ul>
		</div>




	</div>
	<div id="main">
		<div
			style="width: 21%; height: 660px; border-right: 3px #660033 solid; float: left; background-color: rgb(242, 247, 252);"></div>
		<div style="width: 78%; font-size: 22px; float: right">
			<div style="margin-top: 50px; margin-left: 50px; height: 560px">
				<table width="800" border="0"
					style="font-size: 14px; border: 2px solid #999;">
					<tr>
						<td style="border-bottom: 1px #999 dotted;">
							<li style="float: left; width: 80px">事务：</li>
							<li id="delete" style="float: left; width: 80px; cursor: pointer;"
							onclick="deleteLecture()">删除</li>
							<li id="shakeli" style="float: left; width: 80px;" ></li>
							<li id="editor" style="float: left; width: 80px;"></li>
							<li id="showcode" style="float: left; width: 80px">查看验证码</li>
							<li id="showregister" style="float: left; width: 110px">查看摇号结果</li>




							<li id="showcheck" style="float: left; width: 80px">签到结果</li>
							<li style="float: left; width: 80px"><a href="TeacherIndex.html">返回浏览</a></li>


						</td>
					</tr>
					<tr>
						<td style="border-bottom: 1px #999 dotted;">
						<p>手动报名：</p>
							<li >
							<input type="text" id="studentId">
							</li>
							
							<li ><input type="button" value="报名"
								onclick="teacherRegisterLecture()"></li></td>
					</tr>
					<tr>
						<td style="font-size: 16px;"><div id="iteratorProductsTarget">

							</div></td>
					</tr>
				</table>


			</div>
			<div style="font-size: 14px; margin-left: 100px;">
				<span id="online">当前在线人数:</span> <span style="margin-left: 150px">Copyright
					&copy; 2013 经济管理学院 北京市海淀区清华东路35号 邮编：100083</span>
			</div>
		</div>

	</div>

</body>
</html>
